package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.TbReturnOrderItem;
import com.guigu.qingcheng.service.TbReturnOrderItemService;
import com.guigu.qingcheng.utils.PageUtil;
import com.guigu.qingcheng.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
*
* @author Jiang
* @date 2020/07/31
*/
@Slf4j
@RestController
@RequestMapping("/return/order/item")
@Api(tags = "TbReturnOrderItemController")
public class TbReturnOrderItemController {
    @Resource
    private TbReturnOrderItemService tbReturnOrderItemService;

    @ApiOperation(value = "根据id获取信息")
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id") Integer id) {

        TbReturnOrderItem tbReturnOrderItem = tbReturnOrderItemService.findById(id);
        return R.ok().data("tbReturnOrderItem",tbReturnOrderItem);
    }

    @ApiOperation(value = "获取信息（list不分页）")
    @GetMapping("/list")
    public R list() {
        List<TbReturnOrderItem>  list = tbReturnOrderItemService.queryAll();
        return R.ok().data("list",list);
    }



    @ApiOperation(value = "获取信息（list分页）不带条件")
    @GetMapping("/listPages/{pageNum}/{pageSize}")
    public R listPages(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        PageUtil<TbReturnOrderItem> pageUtils = tbReturnOrderItemService.findListAll(pageNum, pageSize);

        return R.ok().data("pageUtils",pageUtils);
    }

    @ApiOperation(value = "获取信息（list分页）带条件")
    @PostMapping("pageQueryByAll/{pageNum}/{pageSize}")
    public R pageQueryByAll(@RequestBody TbReturnOrderItem tbReturnOrderItem, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        PageUtil<TbReturnOrderItem> pageUtils = tbReturnOrderItemService.pageQueryByAll(pageNum, pageSize, tbReturnOrderItem);
        return R.ok().data("pageUtils",pageUtils);
    }

    @ApiOperation(value = "添加信息")
    @PostMapping("/add")
    public R add(@RequestBody TbReturnOrderItem tbReturnOrderItem) {

        boolean b = tbReturnOrderItemService.saveTbReturnOrderItem(tbReturnOrderItem);
        if(b){
            return R.ok().message("添加成功");
        }
        return R.error().message("添加失败");
    }

    @ApiOperation(value = "修改信息")
    @PutMapping("/update")
    public R update(@RequestBody TbReturnOrderItem tbReturnOrderItem) {
        boolean b = tbReturnOrderItemService.updateTbReturnOrderItem(tbReturnOrderItem);

        if(b){
            return R.ok().message("修改成功");
        }
        return R.error().message("修改失败");
    }

    @ApiOperation(value = "删除信息（主键）")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Integer id) {
        boolean b = tbReturnOrderItemService.deleteById(id);
        if(b){
            return R.ok().message("删除成功");
        }
        return R.error().message("删除失败");
    }
}
